package com.soup.lab.tools.faker.source;

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;

public class ClassPathFileSource implements ReaderSource {

    private final String resourceName;
    private final Charset charset;

    public ClassPathFileSource(String resourceName) {
        this(resourceName, Charset.defaultCharset());
    }

    public ClassPathFileSource(String resourceName, Charset charset) {
        this.resourceName = resourceName;
        this.charset = charset;
    }

    @Override
    public InputStream getAsInputStream() throws IOException {
        return getClass().getClassLoader().getResourceAsStream(resourceName);
    }

    @Override
    public Charset getCharset() {
        return charset;
    }
}
